package com.algorithm.cjm.jiaocai.ch5;

/**
 * Created by jieming.chen on 2020/2/3
 */
public class Example25 {

    public static void main(String[] args) {
        float[] f1 = {0 ,0.11f, 0.13f, 0.15f, 0.21f, 0.24f, 0.30f, 0.35f};
        float[] f2 = {0 ,0.12f, 0.16f, 0.21f, 0.23f, 0.25f, 0.24f, 0.34f};
        float[] f3 = {0, 0.08f, 0.12f, 0.20f, 0.24f, 0.26f, 0.30f, 0.35f};
        float[][] arr = {f1, f2, f3};
        // 资金
        int n = 7;
        int[][] a = new int[3][8];

        float[] temp = new float[10];

        for (int j = 0; j <= n; j++) {
            a[0][j] = j;
        }
        for (int i = 1; i < arr.length; i++) {
            for (int j = 0; j <= n; j++) {
                a[i][j] = 0;
                temp[j] = arr[i][j];
            }
            for (int j = 0; j <= n; j++) {
                for (int k = 0; k <= j; k++) {
                    if (f1[j-k] + arr[i][k] > temp[j]) {
                        temp[j] = f1[j-k] + arr[i][k];
                        a[i][j] = k;
                    }
                }
            }
            for (int g = 0; g <= n; g++) {
                f1[g] = temp[g];
            }
        }

        System.out.println(f1);
        System.out.println(a);
    }
}
